<?php
/**
 * 售后订单表
 * @author RenJianHong
 * @date 2021-8-3 9:28
 */
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderRefundTable extends Migration
{
    public $tableName = "order_refund";

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(!Schema::hasTable($this->tableName)) $this->create();
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }

    /**
     * 执行创建表
     */
    private function create()
    {
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->engine = 'InnoDB';      // 设置存储引擎
            $table->charset = 'utf8';       // 设置字符集
            $table->collation  = 'utf8_general_ci';       // 设置排序规则
            $table->index('order_id');//普通索引
            $table->index('user_id');//普通索引

            $table->id();
            $table->integer("user_id")->nullable(false)->default(0)->comment("用户ID");
            $table->integer("order_id")->nullable(false)->default(0)->comment("订单ID");
            $table->integer("order_detail_id")->nullable(false)->default(0)->comment("订单详情ID");
            $table->string("order_refund_no",32)->nullable(false)->default("")->comment("退款单号");
            $table->string("transaction_no")->nullable(true)->default("")->comment("交易单号");
            $table->tinyInteger("refund_type")->nullable(false)->default(0)->comment("售后类型 1--仅退款，2--退款退货，3--换货");
            $table->decimal("refund_price",10,2)->nullable(false)->default(0)->comment("退款金额");
            $table->longText("user_desc")->nullable(true)->comment("退款说明");
            $table->longText("pic_list")->nullable(true)->comment("凭证图片列表：json格式");
            $table->tinyInteger("refund_status")->nullable(false)->default(0)->comment("状态：0--待处理，1--同意并已退款，2--已同意换货，3--已拒绝退换货");
            $table->tinyInteger("refund_pay_type")->nullable(false)->default(0)->comment("退款方式 1--原路返回 2--退回余额 3--线下转账");
            $table->timestamp("response_time")->default(null)->comment("商家处理时间");
            $table->string("refuse_desc",500)->nullable(true)->default("")->comment("拒绝退换货原因");
            $table->tinyInteger("is_user_send")->nullable(false)->default(0)->comment("用户已发货：0--未发货，1--已发货");
            $table->string("user_send_express",32)->nullable(false)->default("")->comment("用户发货快递公司");
            $table->string("user_send_express_no",32)->nullable(false)->default("")->comment("用户发货快递单号");
            $table->integer("refund_address_id")->nullable(false)->default(0)->comment("退换货地址ID");
            $table->tinyInteger("is_agree")->nullable(false)->default(0)->comment("是否已同意退款、退款退货、换货：0--待处理，1--已同意，2--已拒绝");
            $table->tinyInteger("is_delete")->nullable(false)->default(0)->comment("是否删除 0--否 1--是");
            
            $table->timestamps();
            
        });
        DB::statement("ALTER TABLE zzkj_{$this->tableName} comment '售后订单表'");
    }
}
